from django.shortcuts import render
from rest_framework.generics import ListAPIView, RetrieveAPIView
from . import serializers
from .models import Area

# Create your views here.
# /areas/ 获取省,直辖市,自治区,特别行政区等信息
class ProvincePlaceView(ListAPIView):
    """获取省等区划"""
    serializer_class = serializers.ProvincePlaceSerializer
    queryset = Area.objects.filter(parent__isnull=True)


# GET /areas/(?P<pk>\d+)/ 获取单个区划和这个区划的下级
class AreasView(RetrieveAPIView):
    """获取单个区划及其下级的视图"""
    serializer_class = serializers.AreaSerializer
    queryset = Area.objects.all()